package RIP;

import java.io.IOException;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * Cliente TCP, responssavel por enviar e receber objetos (pacotes) entre os nodes
 */
public class clienteTCP extends Thread {

    private Socket clientSocket;
    private pacote clientPacote;
    private int porta;

    public clienteTCP(int port) throws UnknownHostException, IOException {
        porta = port;
        clientSocket = new Socket("localhost", porta);
    }

    public int getPorta() {
        return porta;
    }

    public void run() {

        try {
            ObjectOutputStream outToServer = new ObjectOutputStream(clientSocket.getOutputStream());

            outToServer.writeObject(clientPacote);

            clientSocket.close();

        } catch (Exception e) {
            Logger.getLogger(serverMulthreadTCP.class.getName()).log(Level.SEVERE, null, e);
        }
    }

    public pacote getClientPacote() {
        return clientPacote;
    }

    public void setClientPacote(pacote clientPacote) {
        this.clientPacote = clientPacote;
    }
}
